package com.intellagric.agriecom.controller.agriecom_index;

import com.intellagric.agriecom.module.agriecom_produce.ProduceService;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.module.cms.ContentVo;
import com.intellagric.pojo.AgriecomProduce;
import com.intellagric.pojo.CmsCategoryContent;
import com.intellagric.service.module.cms_content.ContentCategoryService;
import com.intellagric.service.module.cms_content.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Autuor cky
 * @description
 * @Date 20:20 2019/2/23
 */
@Controller
public class ProductRecommendController {

    @Autowired
    public ContentCategoryService categoryService;

    @Autowired
    public ContentService contentService;

    @Autowired
    public ProduceService produceService;

    @Value("${indexProRec.rotationID}")
    private String rotationID;

    @Value("${indexProRec.brandsID}")
    private String brandsID;

    @Value("${indexProRec.advertisementsID}")
    private String advertisementsID;

    /**
     * 大轮播
     * @return
     */
    @RequestMapping("/agriecomIndex/proRecommend/rotation")
    @ResponseBody
    public List<CmsCategoryContent> recommendRotationChart(){
        ContentVo vo=new ContentVo();
        vo.setCategoryId(rotationID);
        LayuiDataGridResult result = contentService.queryContentByVo(1, 3, vo);
        return result.getData();
    }

    /**
     * 亮点商品轮播
     * @return
     */
    @RequestMapping("/agriecomIndex/proRecommend/spotlight")
    @ResponseBody
    public List<AgriecomProduce> recommendSpotlight(@RequestParam(value = "page",defaultValue = "1") int page, @RequestParam(value="limit",defaultValue = "10")int rows){
        LayuiDataGridResult result = produceService.getList(page, rows, null);
        List<AgriecomProduce> list=result.getData();
        for(AgriecomProduce produce:list){
            if(produce.getProduceImg()!=null&&!produce.getProduceImg().equals(""))
                produce.setProduceImg(produce.getProduceImg().split(",")[0]);
        }
        return result.getData();
    }

    /**
     * 商标
     * @return
     */
    @RequestMapping("/agriecomIndex/proRecommend/brands")
    @ResponseBody
    public List<CmsCategoryContent> recommendBrands(){
        ContentVo vo=new ContentVo();
        vo.setCategoryId(brandsID);
        return contentService.queryContentByVo(1,8,vo).getData();
    }

    /**
     * 广告
     * @return
     */
    @RequestMapping("/agriecomIndex/proRecommend/advertise")
    @ResponseBody
    public List<CmsCategoryContent> recommendAdvertise(){
        ContentVo vo=new ContentVo();
        vo.setCategoryId(advertisementsID);
        return contentService.queryContentByVo(1,1,vo).getData();
    }


}
